﻿using System.Collections.Generic;
using System.Web.Mvc;
using Autofac;
using Autofac.Integration.Web;

namespace GBlog.Core
{
    public class GFilterProvider : FilterAttributeFilterProvider
    {
        private IContainerProvider ContainerProvider;
        public GFilterProvider(IContainerProvider ContainerProvider)
        {
            this.ContainerProvider = ContainerProvider;
        }

        public override IEnumerable<Filter> GetFilters(ControllerContext controllerContext, ActionDescriptor actionDescriptor)
        {
            var filters = base.GetFilters(controllerContext, actionDescriptor);
            foreach (var filter in filters)
            {
                ContainerProvider.RequestLifetime.InjectProperties(filter.Instance);
            }
            return filters;
        }
    }
}